package com.itheima.demo02;

import java.io.*;
import java.util.Arrays;

//字符缓冲流操作文件中数据排序案例
public class CharClass05 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        BufferedWriter bw = null;
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader("day12\\a.txt"));
            String str = br.readLine();
            System.out.println("读取到的数组为：" + str);

            String[] split = str.split(" ");
            int[] arr = new int[split.length];
            for (int i = 0; i < split.length; i++) {
                int parseInt = Integer.parseInt(split[i]);
                arr[i] = parseInt;
            }
            Arrays.sort(arr);
            System.out.println(Arrays.toString(arr));
            bw = new BufferedWriter(new FileWriter("day12\\b.txt"));
            bw.write(Arrays.toString(arr));
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (bw != null) {
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("程序运行了" + (end - start) + "毫秒！");
    }
}
